/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ep.m009.bl;

import ep.persistence.controllers.T006PrescriptionJpaController;
import ep.persistence.entities.T006Prescription;
import java.util.Collection;
import javax.persistence.Query;

/**
 *
 * @author Spyros
 */
public class BL009Controller {

    public Collection<T006Prescription> getUnprescripedDosageByPatient(Integer patientId) {
        T006PrescriptionJpaController jpaController = new T006PrescriptionJpaController();
        String queryString = "select distinct p.* "
                + "from t006_prescription p "
                + "inner join t008_dosage d on d.t006_presciption_id = p.id "
                + "where (d.prescribed is null or d.prescribed = 0) "
                + "and p.t005_patient_id = ? ";
        Query query = jpaController.getEntityManager().createNativeQuery(queryString, T006Prescription.class);
        query.setParameter(1, patientId);
        return query.getResultList();
    }
}
